package ldkxingzhe.ldkxingzhedemo.tab;

import android.support.v4.app.Fragment;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.amap.api.maps.offlinemap.OfflineMapCity;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by liangdengke on 2015/9/1.
 */
public class CityListAdapter extends BaseAdapter {

    List<OfflineMapCity> mList;
    private CityListFragment mFragment;
    public CityListAdapter(CityListFragment fragment,List<OfflineMapCity> list){
        mList = list;
        mFragment = fragment;
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public OfflineMapCity getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final OfflineMapCity tmpCity = getItem(position);
        convertView = mFragment.initAdapterGetView(convertView, parent, tmpCity);
        CityItemViewHolder cityItemViewHolder = (CityItemViewHolder)convertView.getTag();
        String tmpString = tmpCity.getCity();
        if(mFragment.isProvince(tmpString)){
            cityItemViewHolder.currentCity.setVisibility(View.VISIBLE);
            cityItemViewHolder.currentCity.setText("(全省)");
        }
        return convertView;
    }
}